import 'package:flutter/material.dart';
import 'package:flutter_changdian_football/widget/screenutil/custom_screenutil.dart';

class OperationalResultsDialog {

  static void show(
    BuildContext mContext, {
      Function? confirmTap,
      String text = '',
      String icon = 'assets/images/img_tc_cg.png'
    }
  ) {
    showDialog(
      barrierDismissible: false,
      context: mContext,
      builder: (BuildContext context) {
        return WillPopScope(
          onWillPop: () async => false,
          child: ShowDialogPage(
            confirmTap: confirmTap,
            text: text,
            icon: icon,
          ),
        );
      }
    );
  }

}




class ShowDialogPage extends Dialog {
  ShowDialogPage({
    this.confirmTap,
    this.text = '',
    this.icon = 'assets/images/img_tc_cg.png'
  });

  // 确认
  final Function? confirmTap;
  final String text;
  final String icon;

  @override
  Widget build(BuildContext dContext) {
    return Material(
      //创建透明层
      type: MaterialType.transparency, //透明类型
      //自定义dialog布局
      child: Center(
        child: RichText(
          text: TextSpan(
            children: [
              WidgetSpan(
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    Stack(
                      clipBehavior: Clip.none,
                      alignment: Alignment.center,
                      children: [
                        Container(
                          margin: EdgeInsets.symmetric(horizontal: 40.w),
                          padding: EdgeInsets.only(top: 26.w, left: 20.w, right: 20.w, bottom: 20.w),
                          width: double.infinity,
                          decoration: BoxDecoration(
                            color: Colors.white,
                            borderRadius: BorderRadius.circular(12.r)
                          ),
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            mainAxisSize: MainAxisSize.min,
                            children: [
                              SizedBox(height: 60.w,),

                              Container(
                                alignment: Alignment.center,
                                child: Text(text, style: TextStyle(fontSize: 18.sp, fontWeight: FontWeight.w500, color: const Color(0xff323232)), textAlign: TextAlign.center,)
                              ),

                              SizedBox(height: 49.w,),

                              SizedBox(
                                child: Row(
                                  children: [
                                    Expanded(
                                      child: GestureDetector(
                                        behavior: HitTestBehavior.translucent,
                                        onTap: () {
                                          confirmTap?.call();
                                        },
                                        child: Container(
                                          padding: EdgeInsets.symmetric(vertical: 12.w),
                                          decoration: BoxDecoration(
                                            color: const Color(0xff499360),
                                            borderRadius: BorderRadius.circular(8.r),
                                            border: Border.all(
                                              width: 1.w,
                                              color: const Color(0xff499360)
                                            )
                                          ),
                                          alignment: Alignment.center,
                                          child: Text('确定', style: TextStyle(fontSize: 14.sp, color: Colors.white, fontWeight: FontWeight.w500),),
                                        ),
                                      ),
                                    )
                                  ],
                                ),
                              ),
                            ],
                          ),
                        ),

                        Positioned(
                          top: -32.w,
                          child: Container(
                            width: 68.w,
                            height: 68.w,
                            decoration: BoxDecoration(
                              borderRadius: BorderRadius.circular(68.r)
                            ),
                            child: Image.asset(icon, fit: BoxFit.fill,),
                          )
                        )
                      ],
                    ),

                  ],
                )
              ),
            ]
          ),
        ),
      )
    );
  }
}
